/*    */ package com.zimbra.cs.service.mail;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.soap.Element;
/*    */ import com.zimbra.common.soap.Element.KeyValuePair;
/*    */ import com.zimbra.common.soap.MailConstants;
/*    */ import com.zimbra.cs.mailbox.MailItem.CustomMetadata;
/*    */ import com.zimbra.cs.mailbox.MailItem.Type;
/*    */ import com.zimbra.cs.mailbox.Mailbox;
/*    */ import com.zimbra.cs.mailbox.OperationContext;
/*    */ import com.zimbra.cs.service.util.ItemId;
/*    */ import com.zimbra.cs.service.util.ItemIdFormatter;
/*    */ import com.zimbra.soap.ZimbraSoapContext;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class SetCustomMetadata
/*    */   extends MailDocumentHandler
/*    */ {
/* 33 */   private static final String[] TARGET_ITEM_PATH = { "id" };
/* 34 */   protected String[] getProxiedIdPath(Element request) { return TARGET_ITEM_PATH; }
/* 35 */   protected boolean checkMountpointProxy(Element request) { return false; }
/*    */   
/*    */   public Element handle(Element request, Map<String, Object> context) throws ServiceException {
/* 38 */     ZimbraSoapContext zsc = getZimbraSoapContext(context);
/* 39 */     Mailbox mbox = getRequestedMailbox(zsc);
/* 40 */     OperationContext octxt = getOperationContext(zsc, context);
/* 41 */     ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
/*    */     
/* 43 */     Element meta = request.getElement("meta");
/* 44 */     String section = meta.getAttribute("section");
/* 45 */     section = section.trim();
/* 46 */     if ((section.length() == 0) || (section.length() > 36)) {
/* 47 */       throw ServiceException.INVALID_REQUEST("invalid length for custom metadata section name", null);
/*    */     }
/* 49 */     MailItem.CustomMetadata custom = new MailItem.CustomMetadata(section);
/* 50 */     for (Element.KeyValuePair kvp : meta.listKeyValuePairs()) {
/* 51 */       custom.put(kvp.getKey(), kvp.getValue());
/*    */     }
/* 53 */     ItemId iid = new ItemId(request.getAttribute("id"), zsc);
/* 54 */     mbox.setCustomData(octxt, iid.getId(), MailItem.Type.UNKNOWN, custom);
/*    */     
/* 56 */     Element response = zsc.createElement(MailConstants.SET_METADATA_RESPONSE);
/* 57 */     response.addAttribute("id", ifmt.formatItemId(iid));
/* 58 */     return response;
/*    */   }
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/mail/SetCustomMetadata.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */